package com.bwie.controller;

import com.bwie.service.SurplusService;
import com.bwie.utils.OSSFileUtil;
import com.bwie.utils.R;
import com.bwie.vo.SurplusVo;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @author : LeiMingkun
 * @date : 2024-08-06 14:28
 * @description : SurplusController
 **/
@RestController
@RequestMapping("/surplus/surplus")
public class SurplusController {
    @Resource
    private OSSFileUtil ossFileUtil;
    @Resource
    private SurplusService surplusService;
    @RequestMapping("/getSurplusList")
    public R getSurplusList(@RequestBody SurplusVo surplusVo){
        return surplusService.getSurplusList(surplusVo);
    }

    @RequestMapping("/insertSurplus")
    public R insertSurplus(@RequestBody SurplusVo surplusVo){
        return surplusService.insertSurplus(surplusVo);
    }
    @Transactional
    @RequestMapping("/insertImages")
    public R insertImages(@RequestBody MultipartFile file) throws IOException {
        String url = ossFileUtil.uploadFile(file);
        return R.success(url);
    }
    @RequestMapping("/updateList")
    public R updateList(){
        return surplusService.updateList();
    }

    @RequestMapping("/findSurplusById/{id}")
    public R findSurplusById(@PathVariable(name = "id")Integer id){
        return surplusService.findSurplusById(id);
    }

    @RequestMapping("/sureUpdate")
    public R sureUpdate(@RequestBody SurplusVo surplusVo){
        return surplusService.sureUpdate(surplusVo);
    }

}